package app.maker.entity;

import java.io.Serializable;

import javax.persistence.*;

import java.util.Date;
import java.util.List;


/**
 * The persistent class for the ticket database table.
 * 
 */
@Entity
@Table(name="ticket")

@NamedQueries({
	@NamedQuery(name="Ticket.findAll", query="SELECT t FROM Ticket t"),
	@NamedQuery(name = "Ticket.findTicketByReference", query = "SELECT t FROM Ticket t WHERE t.reference = :param") })
public class Ticket implements Serializable {
	private static final long serialVersionUID = 1L;
	private int idTicket;
	private String categorie;
	private Date date;
	private String description;
	private String reference;
	private String travauxEffectues;
	private List<TicketHasUser> ticketHasUsers;

	public Ticket() {
	}


	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	@Column(unique=true, nullable=false)
	public int getIdTicket() {
		return this.idTicket;
	}

	public void setIdTicket(int idTicket) {
		this.idTicket = idTicket;
	}


	@Column(length=45)
	public String getCategorie() {
		return this.categorie;
	}

	public void setCategorie(String categorie) {
		this.categorie = categorie;
	}


	@Temporal(TemporalType.DATE)
	@Column(nullable=false)
	public Date getDate() {
		return this.date;
	}

	public void setDate(Date date) {
		this.date = date;
	}


	@Column(nullable=false, length=255)
	public String getDescription() {
		return this.description;
	}

	public void setDescription(String description) {
		this.description = description;
	}


	@Column(nullable=false, length=20, unique=true)
	public String getReference() {
		return this.reference;
	}

	public void setReference(String reference) {
		this.reference = reference;
	}


	@Column(length=255)
	public String getTravauxEffectues() {
		return this.travauxEffectues;
	}

	public void setTravauxEffectues(String travauxEffectues) {
		this.travauxEffectues = travauxEffectues;
	}


	//bi-directional many-to-one association to TicketHasUser
	@OneToMany(mappedBy="ticket", cascade=CascadeType.ALL, fetch=FetchType.EAGER)
	public List<TicketHasUser> getTicketHasUsers() {
		return this.ticketHasUsers;
	}

	public void setTicketHasUsers(List<TicketHasUser> ticketHasUsers) {
		this.ticketHasUsers = ticketHasUsers;
	}

	public TicketHasUser addTicketHasUser(TicketHasUser ticketHasUser) {
		getTicketHasUsers().add(ticketHasUser);
		ticketHasUser.setTicket(this);

		return ticketHasUser;
	}

	public TicketHasUser removeTicketHasUser(TicketHasUser ticketHasUser) {
		getTicketHasUsers().remove(ticketHasUser);
		ticketHasUser.setTicket(null);

		return ticketHasUser;
	}

}